<style type="text/css">
    #danhsach{ 
        width: 700px; min-height: 500px; padding-top: 10px;
        background: gray; float:left; /*overflow: scroll;*/
    }
    #danhsach table{border-collapse:collapse; margin: 0 auto;}
    #danhsach td{ border: 1px solid #000; padding: 5px;}
	#soid{width: 60px; text-align: center; color: #fff;}
	#tieude{width: 100px; text-align: center; color: #fff;}
	#nd{width: 300px; text-align: center; color: #fff;}
	#tgd{width: 100px; text-align: center; color: #fff;}
	.ch{width: 40px; text-align: center; color: #fff;}
    #sub_content{width: 850px; margin:auto}
	#phantrang{width:200px; height:20px; margin:auto;magin-top:20px;}
</style>

<div id="function">
    DANH SÁCH MÔN HỌC
</div>

<div id="sub_content">
    <div id="danhsach" style="background: #fff;">
<?php 
	@include_once "../../app/connection.php";
	?>
		<table>
                <tr style="background: #247CB9;">
                    <td id="soid">ID</td>
                    <td id="tieude">Tiêu đề</td>
                    <td id="nd">Nội dung</td>
                    <td id="tgd">Thời gian đăng</td>
                    <td class="ch">Chọn</td>
                </tr>
<?php
		if(!isset($_GET['subpage'])) // current page
		{
			$p = 1;
		}
		else
		{
			$p = $_GET['subpage'];
		}
		//echo "$p <br/>";
		$row = 10; //so record tren moi trang
		$div = 5; // so trang tren 1 phan doan
		$s = "SELECT * FROM tintuc";
		$rs = mysql_query($s, $connect);
		$total = mysql_num_rows($rs);
		//echo "<br/> $total";
		$start = $p*$row - $row; //vi tri bat dau cua record trong trang
		//echo "<br/> $start";
        $str = "SELECT * FROM tintuc ORDER BY ID DESC LIMIT $start,$row";
        $sql = mysql_query($str, $connect) or die(mysql_error($connect));
		
        while($rw = mysql_fetch_array($sql)) // hien thi du lieu
		{
			echo "<tr><td>".$rw['ID']."</td><td>".$rw['TIEUDE']."</td><td>".$rw['NOIDUNG']."</td><td>".$rw['THOIGIAN']."</td><td class='ch'><input type='checkbox' name='checknews' value='".$rw['ID']."' /></td></tr>";	
		}
?>
        </table>   
    </div>    
    <input type="button" value="Xóa" name="xoa" style="float:right; width:80px;" />     
<?php
	$total_page = ceil($total/$row);
		$list_page = "";
		for($i=1; $i<=$total_page; $i++)
		{
			if($p == $i)
			{
				$list_page .= "<b>".$i." </b>";
			}
			else
			{
				$list_page .= "<a class='news' href=index.php?page=tintuc&function=ds_tintuc&subpage=$i>$i </a>";
			}
		}

		if($p > 1){
			$prev = $p - 1;
			$list_page .= "<a class='news' href=index.php?page=tintuc&function=ds_tintuc&subpage=$prev>Previous</a>";
		}

		if($p < $total_page){
			$prev = $p + 1;
			$list_page .= "<a class='news' href=index.php?page=tintuc&function=ds_tintuc&subpage=$prev>Next</a>";
		}
		//echo "<div id='phantrang'>".$list_page."</div>";
?>
	<div id='phantrang'><?php echo $list_page ?></div> 
</div>

<script language="javascript">
	$(document).ready(function(e) {
        $("input:checkbox[name='checknews']").click(function(e) {
            if($(this).attr('checked'))
				$(this).attr('checked',false);
			else 
				$(this).attr('checked',true);
        });
    });

	$(document).ready(function(e) {
        $("input[name='xoa']").click(function(e) {
			var x = "";
			/*for (var i = 0; i<$("input:checkbox[name='checknews']").is(':checked').length; i++)
			{
				x[i] = $("input:checkbox[name='checknews']:checked").val();
			}*/
			//x = $("input:checkbox[name='checknews']:checked").val();
			$("input:checkbox[name='checknews']:checked").each(function(index, element) {
                //alert($(this).val());
				//x.push($(this).val()+",");
				x += $(this).val()+",";
            });
			//alert(x);
            $.ajax({
				url: "tintuc/xoa_thongbao.php",
				type:"POST",
				data:"value="+x,
				success: function(text)
				{
					//alert("Số file chọn: "+text);
					window.location = "index.php?page=tintuc&function=ds_tintuc";
				}
				});
        });
    });
</script>